function t(t) {
    if (Array.isArray(t)) {
        for (var e = 0, o = Array(t.length); e < t.length; e++) o[e] = t[e];
        return o;
    }
    return Array.from(t);
}

var e = require("../../requests/request.js"), o = getApp();

Page({
    data: {
        winHeightAuto: 0,
        voteList: [],
        method: "vote.topiclist",
        pindex: 1,
        psize: 10,
        source: 107,
        token: "",
        userid: "",
        opid: "",
        t: "",
        RecordCount: 0
    },
    onLoad: function(t) {
        var e = this;
        e.setData({
            voteList: []
        }), this.setData({
            pindex: 1
        }), wx.canIUse("showLoading") && wx.showLoading({
            title: "加载中"
        }), e.GetVoteData(), wx.getSystemInfo({
            success: function(t) {
                /(iPhone|iPad|iPod|iOS)/i.test(t.system) ? e.setData({
                    winHeightAuto: t.windowHeight - 86
                }) : e.setData({
                    winHeightAuto: t.windowHeight
                });
            }
        });
    },
    GetVoteData: function() {
        var o = this, n = wx.getStorageSync("UserToken"), a = wx.getStorageSync("UserId"), i = wx.getStorageSync("opid"), s = new Date(), r = parseInt(s.getTime() / 1e3), c = this.data.pindex > 1 ? wx.getStorageSync("LastUpdatetime") : r;
        e.getVoteList(this.data.method, this.data.pindex, this.data.psize, this.data.source, n, a, i, c, function(e) {
            wx.setStorageSync("LastUpdatetime", e.Data.LastUpdatetime);
            var n = e.Data.List;
            n.length > 0 && n.map(function(t) {
                var e = t.VoteCount;
                t.CreateDate = t.CreateDate.substring(0, 10).split("-").join("."), t.VoteDetails.length > 0 && t.VoteDetails.map(function(t) {
                    t.VoteItemPic = t.VoteItemPic.replace("{0}", "5"), t.VotePercent = e > 0 ? parseInt(100 * t.VoteCount / e) + "%" : "0%";
                });
            }), o.setData({
                voteList: [].concat(t(o.data.voteList), t(n)),
                RecordCount: e.Data.RecordCount
            });
        }, function(t) {}, function(t) {
            wx.canIUse("hideLoading") && wx.hideLoading();
        });
    },
    delVote: function(t) {
        var o = this, n = wx.getStorageSync("UserToken"), a = parseInt(new Date().getTime() / 1e3);
        e.getDelVote("vote.delvote", t.currentTarget.dataset.voteid, this.data.source, n, a, function(t) {
            o.onLoad();
        }, function(t) {}, function(t) {});
    },
    goVoteDetail: function(t) {
        wx.navigateTo({
            url: "../voteDetail/voteDetail?voteid=" + t.currentTarget.dataset.voteid
        });
    },
    returnBtn: function() {
        o.gotoIndex();
    },
    goAddHelp: function() {
        wx.getStorageSync("UserToken") ? wx.navigateTo({
            url: "../addhelp/addhelp"
        }) : wx.navigateTo({
            url: "../my/my"
        });
    },
    scrolltoupper: function(t) {
        console.log(t);
    },
    scrolltolower: function(t) {
        var e = this.data.pindex + 1;
        if (this.setData({
            pindex: e
        }), this.data.RecordCount == this.data.voteList.length) return console.log("到底啦"), 
        !1;
        this.GetVoteData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function(t) {
        "button" === t.from ? console.log("来自页面的按钮") : console.log("来自右上角转发菜单");
        var e = "/pages/helpChose/helpChose?voteid=" + t.target.dataset.voteid;
        return console.log(e), {
            title: "朋友帮选车",
            path: e,
            imageUrl: "http://res.app.yiche.com/wechatapp/share_img.png",
            success: function(t) {
                console.log("转发成功", t);
            },
            fail: function(t) {
                console.log("转发失败", t);
            }
        };
    }
});